<template>
  <div class="ele-body">
    <el-row :gutter="15">
      <el-col :md="6" :sm="8">

      </el-col>
      <el-col :md="18" :sm="16">
        <el-card shadow="never" body-style="padding-top: 5px;">
          <el-tabs v-model="active" class="user-info-tabs">

            <el-form
              ref="infoForm"
              :model="form"
              :rules="rules"
              label-width="150px"
              style="max-width: 550px;padding-top: 40px;"
              @keyup.enter.native="save"
              @submit.native.prevent>
              <el-form-item label="座位预约所需押金">
                <el-input
                  :maxlength="20"
                  onkeyup="value=value.replace(/[^\d]/g,'')"
                  v-model="form.price"
                  placeholder="座位预约所需押金 "
                  clearable/>
              </el-form-item>

              <el-form-item label="签到迟到时间扣除所有押金（分钟）">
                <el-input
                  :maxlength="20"
                  onkeyup="value=value.replace(/[^\d]/g,'')"
                  v-model="form.time"
                  placeholder="签到迟到时间扣除所有押金"
                  clearable/>
              </el-form-item>
              <el-form-item label="签到范围(单位/米)">
                <el-input
                  :maxlength="20"
                  onkeyup="value=value.door_distance(/[^\d]/g,'')"
                  v-model="form.door_distance"
                  placeholder="签到范围"
                  clearable/>
              </el-form-item>

              <el-form-item label="签到已过时间没有超出扣除全部的押金每分钟扣除（金额）">
                <el-input
                  :maxlength="20"
                  onkeyup="value=value.replace(/[^\d]/g,'')"
                  v-model="form.retreat_price"
                  placeholder="签到已过时间没有超出扣除全部的押金每分钟扣除"
                  clearable/>
              </el-form-item>
              <el-form-item label="客户预约订单所得积分（1元等于多少积分）">
                <el-input
                  :maxlength="20"
                  onkeyup="value=value.replace(/[^\d]/g,'')"
                  v-model="form.integral"
                  placeholder="客户预约订单所得积分（1元等于多少积分）"
                  clearable/>
              </el-form-item>

              <el-form-item label="规则说明" prop="content">
                <el-input
                  :rows="3"
                  clearable
                  type="textarea"
                  :maxlength="200"
                  v-model="form.content"
                  placeholder="规则说明"/>
              </el-form-item>

              <el-form-item>
                <el-button
                  type="primary"
                  @click="save"
                  :loading="loading">保存更改
                </el-button>
              </el-form-item>
            </el-form>


          </el-tabs>
        </el-card>
      </el-col>
    </el-row>


  </div>
</template>

<script>
import setting from '@/config/setting';
import uploadImage from '@/components/uploadImage'
import regions from 'ele-admin/packages/regions';
import TinymceEditor from '@/components/TinymceEditor'
import '@riophae/vue-treeselect/dist/vue-treeselect.css';

export default {
  name: 'UserInfo',

  components: {uploadImage, TinymceEditor},
  props: {
    // 弹窗是否打开
    visible: Boolean,
    // 修改回显的数据
    data: Object
  },
  data() {
    return {
      active: 'info',
      // 省市区数据
      regions: regions,
      // 选中的省市区
      city: [],
      // 选中的省市
      provinceCity: [],
      // 选中的省
      province: [],
      // 表单数据
      form: Object.assign({status: 1, is_default: 1}, this.data),
      // 表单验证规则
      rules: {

        // city: [
        //     {required: true, message: '请选择省市区', trigger: 'blur'}
        // ]
      },
      // 提交状态
      loading: false,
      // 是否是修改
      isUpdate: false
    };
  },
  watch: {
    data() {
      if (this.data) {
        this.form = Object.assign({}, this.data);
        // 取值赋予城市组件
        this.city = this.data.city;
        this.isUpdate = true;
      } else {
        this.form = {};
        this.isUpdate = false;
        // 清空省市区控件
        this.city = [];
      }
    }
  },

  mounted() {
    // 获取用户信息
    this.getUserInfo();
  },

  methods: {

    /* 获取当前用户信息 */
    getUserInfo() {
      if (setting.userUrl) {
        this.$http.get('/make/getUserInfo').then((res) => {
          const result = setting.parseUser ? setting.parseUser(res.data) : res.data;
          if (result.code === 0) {
            // 赋予对象值
            this.form = JSON.parse(JSON.stringify(result.data))
            this.city = this.form.city;
          } else {
            this.$message.error(result.msg);
          }
        }).catch((e) => {
          console.error(e);
          this.$message.error(e.message);
        });
      }
    },
    /* 保存更改 */
    save() {
      this.$refs['infoForm'].validate((valid) => {
        if (valid) {
          this.loading = true;
          this.form = Object.assign({}, this.form, {
            city: this.city
          });
          this.$http.post('/make/updateUserInfo', this.form).then(res => {
            this.loading = false;
            if (res.data.code === 0) {
              this.$message.success('保存成功');
            } else {
              this.$message.error(res.data.msg);
            }
          }).catch(e => {
            this.loading = false;
            this.$message.error(e.message);
          });
        } else {
          return false;
        }
      });
    },
    /* 更新visible */
    updateVisible(value) {
      this.$emit('update:visible', value);
    }
  }
}
</script>

<style scoped>
.ele-body {
  padding-bottom: 0;
}

.el-card {
  margin-bottom: 15px;
}

/* 用户资料卡片 */
.user-info-card {
  padding-top: 8px;
  text-align: center;
}

.user-info-card .user-info-avatar-group {
  position: relative;
  cursor: pointer;
  margin: 0 auto;
  width: 110px;
  height: 110px;
  border-radius: 50%;
  overflow: hidden;
}

.user-info-card .user-info-avatar {
  width: 110px;
  height: 110px;
  border-radius: 50%;
  object-fit: cover;
}

.user-info-card .user-info-avatar-group > i {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  color: #FFF;
  font-size: 30px;
  display: none;
  z-index: 2;
}

.user-info-card .user-info-avatar-group:hover > i {
  display: block;
}

.user-info-card .user-info-avatar-group:hover:after {
  content: "";
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background-color: rgba(0, 0, 0, .3);
}

.user-info-card .user-info-name {
  font-size: 24px;
  margin-top: 20px;
}

.user-info-card .user-info-desc {
  margin-top: 8px;
}

/* 用户信息列表 */
.user-info-list {
  margin-top: 30px;
}

.user-info-list .user-info-item {
  margin-bottom: 10px;
  display: flex;
  align-items: baseline;
}

.user-info-item > i {
  margin-right: 10px;
  font-size: 16px;
}

.user-info-item > span {
  flex: 1;
  display: block;
}

/* 用户标签 */
.user-info-tags .el-tag {
  margin: 10px 10px 0 0;
}

/* 用户账号绑定列表 */
.user-account-list {
  margin-top: 10px;
}

.user-account-list .user-account-item {
  padding: 15px;
}

.user-account-list .user-account-item .ele-text-secondary {
  margin-top: 6px;
}

.user-account-list .user-account-item .user-account-icon {
  width: 42px;
  height: 42px;
  line-height: 42px;
  text-align: center;
  color: #FFF;
  font-size: 26px;
  border-radius: 50%;
  background-color: #3492ED;
  box-sizing: border-box;
}

.user-account-list .user-account-item .user-account-icon.el-icon-_wechat {
  background-color: #4DAF29;
  font-size: 28px;
}

.user-account-list .user-account-item .user-account-icon.el-icon-_alipay {
  background-color: #1476FE;
  padding-left: 5px;
  font-size: 32px;
}

/* tab页签 */
.user-info-tabs ::v-deep .el-tabs__nav-wrap {
  padding-left: 20px;
}
</style>
